﻿@using Enter.Admin.Utils
@using Enter.Admin.Entities
@using Enter.Admin.Dtoes
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
@inject IFreeSql Fsql
@{
    //@using Microsoft.Extensions.Configuration
    //@inject IConfiguration Configuration
    var menuController = ViewContext.RouteData.Values["controller"].ToString();
    var menuAction = ViewContext.RouteData.Values["action"].ToString();
    var sidebarMenu = new List<SidebarMenu>();// Configuration.GetSection("sidebarMenu").Get<List<SidebarMenu>>();
    {
        var menu = new SidebarMenu()
        {
            Controller = "Home",
            Icon = "fab fa-simplybuilt",
            Text = "档案管理",
            Children = new List<SidebarMenu> {
                new SidebarMenu{
                    Controller = "Case",
                    Action = "Index1",
                    Text = "新一贷（移交特管）",
                },
                new SidebarMenu{
                    Controller = "Case",
                    Action = "Index2",
                    Text = "案件台账总表",
                },
                new SidebarMenu{
                    Controller = "Case",
                    Action = "Index3",
                    Text = "贷贷卡台账",
                },
            },
        };
        sidebarMenu.Add(menu);
    }
    {
        var menu = new SidebarMenu()
        {
            Controller = "Attachment",
            Icon = "fa fa-file",
            Text = "文件管理",
            Children = new List<SidebarMenu> {
                new SidebarMenu{
                    Controller = "Attachment",
                    Action = "Index",
                    Text = "模板管理",
                },
                //new SidebarMenu{
                //    Controller = "Attachment",
                //    Action = "Index2",
                //    Text = "附件管理",
                //}
            },
        };
        sidebarMenu.Add(menu);
    }
    var session = HttpContextAccessor.HttpContext.Session.Get<Employ>();
    if (session != null && session.Role.IsDefault)
    {
        var menu = new SidebarMenu()
        {
            Controller = "User",
            Icon = "fa fa-th-large",
            Text = "系统设置",
            Children = new List<SidebarMenu> {
                new SidebarMenu{
                    Controller = "Role",
                    Action = "Index",
                    Text = "角色管理",
                },
                new SidebarMenu{
                    Controller = "User",
                    Action = "Index",
                    Text = "用户管理",
                },
                new SidebarMenu{
                    Controller = "Setting",
                    Action = "Index",
                    Text = "配置管理",
                },
            },
        };
        sidebarMenu.Add(menu);
    }
    // IOptions<List<SidebarMenu>> mySettings
    var currDate = DateTime.Now.Date;
    var calendars = new Dictionary<DateTime,CalendarModel>();
    if (session != null) {
        var archives = Fsql.Select<CalendarSelectModel>().Where(t => t.IsDeleted == false
        && (t.ChargeUserId1 == session.Id || t.ChargeUserId2 == session.Id)
        && (
        (t.SealOutTime.Date >= currDate && t.SealOutTime.Date <= currDate.AddDays(45))
        || (t.RenewalTime.Date >= currDate && t.RenewalTime.Date <= currDate.AddDays(45))
        || (t.CourtTime.Date >= currDate && t.CourtTime.Date <= currDate.AddDays(10))
        )
        ).ToList();

        foreach (var t in archives)
        {
            var SealOutTimeDate = t.SealOutTime.Date;
            var RenewalTimeDate = t.RenewalTime.Date;
            var CourtTimeDate = t.CourtTime.Date;
            if (SealOutTimeDate >= currDate && SealOutTimeDate <= currDate.AddDays(45))
            {
                if (!calendars.ContainsKey(SealOutTimeDate))
                {
                    calendars.Add(SealOutTimeDate, new CalendarModel(SealOutTimeDate));
                }
                calendars[SealOutTimeDate].SealOutTimeCount++;
            }
            if (RenewalTimeDate >= currDate && RenewalTimeDate <= currDate.AddDays(45))
            {
                if (!calendars.ContainsKey(RenewalTimeDate))
                {
                    calendars.Add(RenewalTimeDate, new CalendarModel(RenewalTimeDate));
                }
                calendars[RenewalTimeDate].RenewalTimeCount++;
            }
            if (CourtTimeDate >= currDate && CourtTimeDate <= currDate.AddDays(10))
            {
                if (!calendars.ContainsKey(CourtTimeDate))
                {
                    calendars.Add(CourtTimeDate, new CalendarModel(CourtTimeDate));
                }
                calendars[CourtTimeDate].CourtTimeCount++;
            }
        }
    }

}

<!-- BEGIN #sidebar -->
<div id="sidebar" class="sidebar @ViewData["PageSidebarClass"]">
    <!-- BEGIN scrollbar -->
    <div data-scrollbar="true" data-height="100%">
        <!-- BEGIN nav -->
        @*<ul class="nav">
                   <li class="nav-profile">
                       <a href="javascript:;" data-toggle="nav-profile">
                           <div class="cover with-shadow"></div>
                           <div class="image">
                               <img src="~/img/user/user-13.jpg" alt="" />
                           </div>
                           <div class="info">
                               <
            * b class="caret pull-right"></b> Sean Ngu
                               <small>Front end developer</small>
                           </div>
                       </a>
                   </li>
                   <li>
                       <ul class="nav nav-profile">
                           <li><a href="javascript:;"><i class="fa fa-cog"></i> Settings</a></li>
                           <li><a href="javascript:;"><i class="fa fa-pencil-alt"></i> Send Feedback</a></li>
                           <li><a href="javascript:;"><i class="fa fa-question-circle"></i> Helps</a></li>



                        </ul>
                   </li>
               </ul>*@
        <!-- end sidebar user -->
        <!-- begin sidebar nav -->
        <ul class="nav">
            @if (ViewData["PageSidebarSearch"] != null)
            {
                <li class="nav-search">
                    <input type="text" class="form-control" placeholder="Sidebar menu filter..." data-sidebar-search="true" />
                </li>
            }

            <li class="nav-header">菜单导航</li>
            @foreach (var menu in sidebarMenu)
            {
                var menuChildren = menu.Children;

                <li class="@(menu.Actived(menuController,menuAction) ? "active" : "") @(menuChildren?.Count > 0 ? "has-sub" : "")">
                    @if (menuChildren?.Count == 0)
                    {
                        <a asp-controller="@menu.Controller" asp-action="@menu.Action">
                            @if (!string.IsNullOrWhiteSpace(menu.Badge))
                            {
                                <span class="badge pull-right">@menu.Badge</span>
                            }
                            @if (!string.IsNullOrWhiteSpace(menu.Icon))
                            {
                                <i class="@menu.Icon"></i>
                            }
                            @if (!string.IsNullOrWhiteSpace(menu.Img))
                            {
                                <div class="icon-img">
                                    <img src="@menu.Img" alt="" />
                                </div>
                            }
                            <span>
                                @menu.Text

                                @if (!string.IsNullOrWhiteSpace(menu.Label))
                                {
                                    <span class="label label-theme">@menu.Label</span>
                                }
                            </span>
                        </a>
                    }
                    else
                    {
                        <a href="javascript:;">
                            @if (menuChildren?.Count > 0)
                            {
                                <b class="caret"></b>
                            }
                            @if (!string.IsNullOrWhiteSpace(menu.Icon))
                            {
                                <i class="@menu.Icon"></i>
                            }
                            @if (!string.IsNullOrWhiteSpace(menu.Img))
                            {
                                <div class="icon-img">
                                    <img src="~@menu.Img" alt="" />
                                </div>
                            }
                            <span>
                                @menu.Text

                                @if (!string.IsNullOrWhiteSpace(menu.Label))
                                {
                                    <span class="label label-theme">@menu.Label</span>
                                }
                            </span>
                        </a>
                    }
                    @if (menuChildren?.Count > 0)
                    {
                        <ul class="sub-menu">
                            @foreach (var submenu in menuChildren)
                            {
                                var menuChildrenLvl1 = submenu.Children;

                                <li class="@(submenu.Actived(menuController, menuAction) ? "active" : "") @(menuChildrenLvl1?.Count > 0 ? "has-sub" : "")">
                                    @if (menuChildrenLvl1?.Count == 0)
                                    {
                                        <a asp-controller="@submenu.Controller" asp-action="@submenu.Action">
                                            @submenu.Text

                                            @if (submenu.Highlight)
                                            {
                                                <i class="fa fa-paper-plane text-theme"></i>
                                            }
                                        </a>
                                    }
                                    else
                                    {
                                        <a asp-controller="@submenu.Controller" asp-action="@submenu.Action">
                                            @if (menuChildrenLvl1?.Count > 0)
                                            {
                                                <b class="caret"></b>
                                            }
                                            <span>
                                                @submenu.Text
                                                @if (submenu.Highlight)
                                                {
                                                    <i class="fa fa-paper-plane text-theme"></i>
                                                }
                                            </span>
                                        </a>
                                    }
                                    @if (menuChildrenLvl1?.Count > 0)
                                    {
                                        <ul class="sub-menu">
                                            @foreach (var submenu2 in menuChildrenLvl1)
                                            {
                                                var menuChildrenLvl2 = submenu2.Children;

                                                <li class="@(submenu2.Actived(menuController, menuAction) ? "active" : "") @(menuChildrenLvl2?.Count > 0 ? "has-sub" : "")">
                                                    @if (menuChildrenLvl2?.Count == 0)
                                                    {
                                                        <a asp-controller="@submenu2.Controller" asp-action="@submenu2.Action">
                                                            @submenu2.Text

                                                            @if (submenu2.Highlight)
                                                            {
                                                                <i class="fa fa-paper-plane text-theme"></i>
                                                            }
                                                        </a>
                                                    }
                                                    else
                                                    {
                                                        <a asp-controller="@submenu2.Controller" asp-action="@submenu2.Action">
                                                            @if (menuChildrenLvl2?.Count > 0)
                                                            {
                                                                <b class="caret"></b>
                                                            }
                                                            <span>
                                                                @submenu2.Text
                                                                @if (submenu2.Highlight)
                                                                {
                                                                    <i class="fa fa-paper-plane text-theme"></i>
                                                                }
                                                            </span>
                                                        </a>

                                                        @if (menuChildrenLvl2?.Count > 0)
                                                        {
                                                            <ul class="sub-menu">
                                                                @foreach (var submenu3 in menuChildrenLvl2)
                                                                {
                                                                    <li class="@(submenu3.Actived(menuController, menuAction) ? "active" : "") @(menuChildrenLvl2?.Count > 0 ? "has-sub" : "")">
                                                                        @if (menuChildrenLvl2?.Count == 0)
                                                                        {
                                                                            <a asp-controller="@submenu3.Controller" asp-action="@submenu3.Action">
                                                                                @submenu3.Text

                                                                                @if (submenu3.Highlight)
                                                                                {
                                                                                    <i class="fa fa-paper-plane text-theme"></i>
                                                                                }
                                                                            </a>
                                                                        }
                                                                        else
                                                                        {
                                                                            <a href="javascript:;">
                                                                                <span>
                                                                                    @submenu3.Text
                                                                                    @if (submenu3.Highlight)
                                                                                    {
                                                                                        <i class="fa fa-paper-plane text-theme"></i>
                                                                                    }
                                                                                </span>
                                                                            </a>
                                                                        }
                                                                    </li>
                                                                }
                                                            </ul>
                                                        }
                                                    }
                                                </li>
                                            }
                                        </ul>
                                    }
                                </li>
                            }
                        </ul>
                    }
                </li>

            }
        </ul>
        <!-- END nav -->
        <div style="position: absolute; bottom: 0px; overflow: hidden; width: 99%;@(calendars.Count >0 ?"":"display:none;")">
            <!-- begin panel -->
            <div class="panel panel-inverse" data-sortable-id="index-0">
                <div class="panel-heading">
                    <h4 class="panel-title">日历</h4>
                    <div class="panel-heading-btn">
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-valign-middle table-panel mb-0">
                        <thead>
                            <tr>
                                <th>日期</th>
                                <th>案件</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var calendar in calendars)
                            {
                                <tr>
                                    <td><label class="label @(calendar.Key <= currDate.AddDays(3) ? "label-danger":"label-warning")">@calendar.Key.ToString("MM-dd")</label></td>
                                    <td>@calendar.Value.Message</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- end panel -->
        </div>
    </div>
    <!-- END scrollbar -->
</div>

<div class="sidebar-bg"></div>
<!-- END #sidebar -->